Skip to content

fix: prevent Next from defining duplicate global property in edge functions #1682

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 17, 2022

Conversation

ascorbic
Copy link
Contributor

Summary

Currently Next.js creates a global function in the edge runtime called __import_unsupported by defining it as an immutable property on globalThis. This means that if there is more than one of these definitions in a single edge function bundle then there is an error when they both try to define it. This PR patches the generated bundle (yeah, I know) to add a check before defining it. I suppose I could try contributing upstream.

The only scenario where this happens now is if you have more than one Next.js edge function or middleware. This means that you need to define an API route to use experimental-edge runtime, and also have middleware.

Test plan

  1. Visit the middleware deploy preview
  2. Load the edge API page /api/edge

Relevant links (GitHub issues, Notion docs, etc.) or a picture of cute animal

image

Standard checks:

  • Check the Deploy Preview's Demo site for your PR's functionality
  • Add docs when necessary

🧪 Once merged, make sure to update the version if needed and that it was published correctly.

@ascorbic ascorbic requested a review from a team October 14, 2022 16:35
@netlify
Copy link

netlify bot commented Oct 14, 2022

Deploy Preview for netlify-plugin-nextjs-nx-monorepo-demo ready!

Name Link
🔨 Latest commit f346599
🔍 Latest deploy log https://app.netlify.com/sites/netlify-plugin-nextjs-nx-monorepo-demo/deploys/634d0f04f69389000883958e
😎 Deploy Preview https://deploy-preview-1682--netlify-plugin-nextjs-nx-monorepo-demo.netlify.app/
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@netlify
Copy link

netlify bot commented Oct 14, 2022

Deploy Preview for netlify-plugin-nextjs-demo ready!

Name Link
🔨 Latest commit f346599
🔍 Latest deploy log https://app.netlify.com/sites/netlify-plugin-nextjs-demo/deploys/634d0f0305d4e1000996b301
😎 Deploy Preview https://deploy-preview-1682--netlify-plugin-nextjs-demo.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@netlify
Copy link

netlify bot commented Oct 14, 2022

Deploy Preview for next-plugin-canary ready!

Name Link
🔨 Latest commit f346599
🔍 Latest deploy log https://app.netlify.com/sites/next-plugin-canary/deploys/634d0f0404c53000090b6ea3
😎 Deploy Preview https://deploy-preview-1682--next-plugin-canary.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@github-actions github-actions bot added the type: bug code to address defects in shipped code label Oct 14, 2022
Comment on lines -100 to -103
const middleware = await fs.readFile(join(publish, `server`, `${edgeFunctionDefinition.name}.js`), 'utf8')

chunks.push(middleware)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't needed anymore, because the middleware file itself is included in edgeFunctionDefinition.files

@netlify
Copy link

netlify bot commented Oct 14, 2022

Deploy Preview for next-plugin-rsc-demo ready!

Name Link
🔨 Latest commit f346599
🔍 Latest deploy log https://app.netlify.com/sites/next-plugin-rsc-demo/deploys/634d0f048c8f1d00087ec033
😎 Deploy Preview https://deploy-preview-1682--next-plugin-rsc-demo.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@netlify
Copy link

netlify bot commented Oct 14, 2022

Deploy Preview for next-i18next-demo ready!

Name Link
🔨 Latest commit f346599
🔍 Latest deploy log https://app.netlify.com/sites/next-i18next-demo/deploys/634d0f04f3bbee000989bd82
😎 Deploy Preview https://deploy-preview-1682--next-i18next-demo.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@netlify
Copy link

netlify bot commented Oct 14, 2022

Deploy Preview for nextjs-plugin-custom-routes-demo ready!

Name Link
🔨 Latest commit f346599
🔍 Latest deploy log https://app.netlify.com/sites/nextjs-plugin-custom-routes-demo/deploys/634d0f04452352000910fb90
😎 Deploy Preview https://deploy-preview-1682--nextjs-plugin-custom-routes-demo.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@netlify
Copy link

netlify bot commented Oct 14, 2022

Deploy Preview for netlify-plugin-nextjs-static-root-demo ready!

Name Link
🔨 Latest commit f346599
🔍 Latest deploy log https://app.netlify.com/sites/netlify-plugin-nextjs-static-root-demo/deploys/634d0f048c8f1d00087ec029
😎 Deploy Preview https://deploy-preview-1682--netlify-plugin-nextjs-static-root-demo.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@netlify
Copy link

netlify bot commented Oct 14, 2022

Deploy Preview for next-plugin-edge-middleware ready!

Name Link
🔨 Latest commit f346599
🔍 Latest deploy log https://app.netlify.com/sites/next-plugin-edge-middleware/deploys/634d0f04effcc300090824ba
😎 Deploy Preview https://deploy-preview-1682--next-plugin-edge-middleware.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@netlify
Copy link

netlify bot commented Oct 14, 2022

Deploy Preview for netlify-plugin-nextjs-next-auth-demo ready!

Name Link
🔨 Latest commit f346599
🔍 Latest deploy log https://app.netlify.com/sites/netlify-plugin-nextjs-next-auth-demo/deploys/634d0f042b182500095a17eb
😎 Deploy Preview https://deploy-preview-1682--netlify-plugin-nextjs-next-auth-demo.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@netlify
Copy link

netlify bot commented Oct 14, 2022

Deploy Preview for netlify-plugin-nextjs-export-demo ready!

Name Link
🔨 Latest commit f346599
🔍 Latest deploy log https://app.netlify.com/sites/netlify-plugin-nextjs-export-demo/deploys/634d0f04325d63000806d42b
😎 Deploy Preview https://deploy-preview-1682--netlify-plugin-nextjs-export-demo.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@ascorbic ascorbic force-pushed the mk/import-unspported branch from cd5ac2d to eefbe46 Compare October 14, 2022 16:47
@kodiakhq kodiakhq bot merged commit 730df6b into main Oct 17, 2022
@kodiakhq kodiakhq bot deleted the mk/import-unspported branch October 17, 2022 08:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automerge type: bug code to address defects in shipped code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants